package com.pj.wisdomlogistics.mvp.presenter;


import com.pj.wisdomlogistics.entity.ApplyDetailInfo;
import com.pj.wisdomlogistics.mvp.contract.ApplyDetailContract;
import com.pj.wisdomlogistics.mvp.frame.ActivityPresenter;
import com.pj.wisdomlogistics.mvp.model.ApplyDetailModel;
import com.pj.wisdomlogistics.rx.FilterSubscriber;

import java.io.File;


public class ApplyDetailPresenter extends ActivityPresenter<ApplyDetailModel, ApplyDetailContract.View> implements ApplyDetailContract.Presenter {
    public static final String TAG = "ApplyDetailPresenter";

    @Override
    public void findMeetingApplyDetail(int meetingApplyID) {
        addSubscription(getModel().findMeetingApplyDetail(meetingApplyID), new FilterSubscriber<ApplyDetailInfo>() {
            @Override
            public void onNext(ApplyDetailInfo mInfo) {
                getView().onSuccess(mInfo);
            }

            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

        });
    }

    @Override
    public void meetingApplySign(int meetingApplyID, String userID, File sign, int state, String comment, final int isSign) {
        addSubscription(getModel().meetingApplySign(meetingApplyID, userID, sign, state, comment), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onSignSuccess(isSign);
            }
        });
    }

    @Override
    public void meetingApplyReview(int meetingApplyID, String userID, String comment, int state) {
        addSubscription(getModel().meetingApplyReview(meetingApplyID,
                userID,
                comment,
                state), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onCheckSuccess();
            }
        });
    }


    @Override
    public void meetingApplyAllot(int meetingApplyID, String userID, String comment, String serverIDs, int state, final int isSign) {
        addSubscription(getModel().meetingApplyAllot(meetingApplyID, userID, comment, serverIDs, state), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().portionSuccess(isSign);
            }
        });
    }

    @Override
    public void meetingApplyKZ(String userID, String meetingApplyID, String state, String comment) {
        addSubscription(getModel().meetingApplyKZ(userID, meetingApplyID, state, comment), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().agreeSuccess();
            }
        });
    }

    @Override
    public void cancelMeetingApply(int meetingApplyID) {
        addSubscription(getModel().cancelMeetingApply(meetingApplyID), new FilterSubscriber() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorMsg);
            }

            @Override
            public void onNext(Object mO) {
                getView().onUndoSuccess();
            }
        });
    }
}
